from flask import Blueprint, jsonify, request
from flask_login import login_required, current_user
from app.repositories.movie_repo import MovieRepository

movie_bp = Blueprint('movies', __name__)
movie_repo = MovieRepository()

@movie_bp.route('/favorites', methods=['POST'])
@login_required
def add_favorite():
    data = request.json
    movie_id = data.get('movie_id')
    favorites = movie_repo.add_favorite(current_user.id, movie_id)
    return jsonify({"favorites": favorites}), 201

@movie_bp.route('/favorites', methods=['GET'])
@login_required
def get_favorites():
    return jsonify({"favorites": movie_repo.get_favorites(current_user.id)}), 200
